﻿@implements IDisposable
<button @onclick="() => Number++" />
<p>@Number</p>
@code {
    public static Dictionary<string, int> CreateDefaultCallLog() => new Dictionary<string, int>
{
        { nameof(SetParametersAsync), 0 },
        { nameof(OnInitialized), 0 },
        { nameof(OnInitializedAsync), 0 },
        { nameof(OnParametersSet), 0 },
        { nameof(OnParametersSetAsync), 0 },
        { nameof(OnAfterRender)+"FirstRender", 0 },
        { nameof(OnAfterRenderAsync)+"FirstRender", 0 },
        { nameof(OnAfterRender), 0 },
        { nameof(OnAfterRenderAsync), 0 },
        { nameof(Dispose), 0 }
    };

    [Parameter] public Dictionary<string, int> CallLog { get; set; } = CreateDefaultCallLog();

    [Parameter] public int Number { get; set; }

    public override Task SetParametersAsync(ParameterView parameters)
    {
        CallLog[nameof(SetParametersAsync)] += 1;
        return base.SetParametersAsync(parameters);
    }

    protected override void OnInitialized() => CallLog[nameof(OnInitialized)] += 1;

    protected override Task OnInitializedAsync()
    {
        CallLog[nameof(OnInitializedAsync)] += 1;
        return Task.CompletedTask;
    }

    protected override void OnParametersSet() => CallLog[nameof(OnParametersSet)] += 1;

    protected override Task OnParametersSetAsync()
    {
        CallLog[nameof(OnParametersSetAsync)] += 1;
        return base.OnParametersSetAsync();
    }

    protected override void OnAfterRender(bool firstRender)
    {
        CallLog[nameof(OnAfterRender) + (firstRender ? "FirstRender" : "")] += 1;
    }

    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        CallLog[nameof(OnAfterRenderAsync) + (firstRender ? "FirstRender" : "")] += 1;
        return base.OnAfterRenderAsync(firstRender);
    }

    public void Dispose()
    {
        CallLog[nameof(Dispose)] += 1;
    }
}